Skip to content

feat: Add player age eligibility validation for leagues#38

Open
hoegertn wants to merge 4 commits intomainfrom
claude/add-player-eligibility-check-017sye2nYis8gpndtkJ2SeZb
Open

feat: Add player age eligibility validation for leagues#38
hoegertn wants to merge 4 commits intomainfrom
claude/add-player-eligibility-check-017sye2nYis8gpndtkJ2SeZb

Conversation

@hoegertn
Copy link
Copy Markdown
Member

@hoegertn hoegertn commented Nov 23, 2025

Add functions to validate if a player is eligible to participate in a league by comparing their dateOfBirth against the league's minAge and maxAge restrictions:

  • calculateAge: Utility to compute age from date of birth
  • checkPlayerEligibility: Returns validation result with errors
  • validatePlayerEligibility: Throws error if ineligible
  • isPlayerEligible: Returns boolean for eligibility

Includes comprehensive tests for all edge cases including boundary conditions, missing data, and invalid formats.

Summary by CodeRabbit

  • New Features

    • Added age-based player eligibility checks: age calculation, eligibility evaluation, and a validator that enforces rules.
  • Documentation

    • Expanded function docs with detailed parameter descriptions, return values, and usage notes for the new validation capabilities.
  • Content Updates

    • Updated site navigation and in-page search payloads to reflect current documentation content.

Add functions to validate if a player is eligible to participate in a
league by comparing their dateOfBirth against the league's minAge and
maxAge restrictions:

- calculateAge: Utility to compute age from date of birth
- checkPlayerEligibility: Returns validation result with errors
- validatePlayerEligibility: Throws error if ineligible
- isPlayerEligible: Returns boolean for eligibility

Includes comprehensive tests for all edge cases including boundary
conditions, missing data, and invalid formats.
@amazon-inspector-frankfurt
Copy link
Copy Markdown

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@github-actions github-actions bot requested a review from hoegerma November 23, 2025 16:36
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 23, 2025

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c5b224ed-d23b-4542-8b56-77b87073da75

📥 Commits

Reviewing files that changed from the base of the PR and between c2170a5 and 0922b9a.

📒 Files selected for processing (3)
  • docs/assets/navigation.js
  • docs/assets/search.js
  • docs/modules.html
✅ Files skipped from review due to trivial changes (2)
  • docs/assets/navigation.js
  • docs/assets/search.js

📝 Walkthrough

Walkthrough

This PR adds four new age-based validation utilities to src/validation.ts, expands and adds HTML documentation pages for those functions, updates tests to cover the new behavior, and refreshes two documentation asset payloads (navigation.js, search.js).

Changes

Cohort / File(s) Summary
Asset Payload Updates
docs/assets/navigation.js, docs/assets/search.js
Replaced the base64-encoded payload strings assigned to window.navigationData and window.searchData; no surrounding logic changed.
Function Documentation
docs/functions/calculateAge.html, docs/functions/checkPlayerEligibility.html, docs/functions/isPlayerEligible.html, docs/functions/validatePlayerEligibility.html
Added/expanded HTML docs with function signatures, parameter descriptions (dateOfBirth in AWSDate YYYY-MM-DD, min/max age, referenceDate), and return details.
Validation Implementation
src/validation.ts
Added exports: calculateAge, checkPlayerEligibility, validatePlayerEligibility, isPlayerEligible. Includes date validation, age computation, and rule checks producing ValidationCheckResult or throwing for invalid eligibility.
Test Suite
test/validation.test.ts
Extended tests to exercise the new functions across edge cases, boundary ages, invalid/nullable dates, and success/error paths.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant ValidateFunc as validatePlayerEligibility()
    participant CheckFunc as checkPlayerEligibility()
    participant CalcFunc as calculateAge()

    Client->>ValidateFunc: (dateOfBirth, minAge, maxAge, referenceDate)
    ValidateFunc->>CheckFunc: (dateOfBirth, minAge, maxAge, referenceDate)
    CheckFunc->>CalcFunc: (dateOfBirth, referenceDate)
    CalcFunc-->>CheckFunc: age (number | null)
    
    alt Valid input & within constraints
        CheckFunc-->>ValidateFunc: ValidationCheckResult (valid)
        ValidateFunc-->>Client: returns void (success)
    else Invalid input or out-of-bounds
        CheckFunc-->>ValidateFunc: ValidationCheckResult (errors)
        ValidateFunc->>Client: throws Error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • fix: exports #34: Updates the same docs/assets files by replacing the base64 payloads assigned to window.navigationData and window.searchData.

Suggested reviewers

  • hoegerma

Poem

🐰 I nibble dates and bounds with cheer,
I count the years that bring us near.
If age fits snug within the frame,
I stamp "eligible" — that's my game!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description covers the key new functions and their purposes, and mentions comprehensive tests. However, it does not follow the repository's template structure (checklist items, change type, behavior sections) and lacks some template elements. Use the repository's PR description template structure including the checklist, change type classification, and behavior sections for consistency and clarity.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding player age eligibility validation for leagues, which aligns with the core functionality introduced across validation functions and tests.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/add-player-eligibility-check-017sye2nYis8gpndtkJ2SeZb

Comment @coderabbitai help to get the list of available commands and usage tips.

@taimos-projen taimos-projen bot enabled auto-merge November 23, 2025 16:36
@amazon-inspector-frankfurt
Copy link
Copy Markdown

✅ I finished the code review, and didn't find any security or code quality issues.

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/validation.test.ts (1)

967-1006: Good coverage, but missing timezone edge case tests.

The test suite covers the main scenarios well. However, it doesn't expose the timezone bug in calculateAge because all tests use explicit date strings for referenceDate (which are parsed as UTC, matching the UTC parsing of dateOfBirth).

Consider adding a test that uses the current time in a specific timezone to ensure the fix handles timezone correctly:

it('should handle timezone correctly when using current time', () => {
  // Test that would expose the timezone bug if not using UTC methods
  const birthDate = '2000-01-01';
  const age = calculateAge(birthDate, new Date(2024, 0, 1, 12, 0, 0)); // January 1, 2024 noon local time
  expect(age).toBe(24);
});

This test would fail with the current implementation in timezones west of UTC.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 339d4ef and c2170a5.

📒 Files selected for processing (8)
  • docs/assets/navigation.js (1 hunks)
  • docs/assets/search.js (1 hunks)
  • docs/functions/calculateAge.html (1 hunks)
  • docs/functions/checkPlayerEligibility.html (1 hunks)
  • docs/functions/isPlayerEligible.html (1 hunks)
  • docs/functions/validatePlayerEligibility.html (1 hunks)
  • src/validation.ts (1 hunks)
  • test/validation.test.ts (2 hunks)
🔇 Additional comments (12)
docs/assets/navigation.js (1)

1-1: LGTM - Generated documentation artifact.

This is a generated navigation data payload that reflects the new API surface. No action required.

docs/assets/search.js (1)

1-1: LGTM - Generated documentation artifact.

This is a generated search index that reflects the new API surface. No action required.

docs/functions/calculateAge.html (1)

1-5: LGTM - Generated documentation page.

The documentation accurately describes the calculateAge function's parameters and return type. No action required.

docs/functions/checkPlayerEligibility.html (1)

1-7: LGTM - Generated documentation page.

The documentation accurately describes the checkPlayerEligibility function's parameters and return type. No action required.

docs/functions/validatePlayerEligibility.html (1)

1-7: LGTM - Generated documentation page.

The documentation accurately describes the validatePlayerEligibility function's throwing behavior. No action required.

docs/functions/isPlayerEligible.html (1)

1-7: LGTM - Generated documentation page.

The documentation accurately describes the isPlayerEligible function's boolean return value. No action required.

src/validation.ts (3)

523-560: LGTM - Solid validation logic.

The age eligibility validation correctly handles all edge cases:

  • Returns no errors when no age restrictions are set
  • Validates that dateOfBirth is provided when restrictions exist
  • Delegates to calculateAge for date parsing and age computation
  • Checks both minimum and maximum age constraints with clear error messages

The use of != null properly catches both null and undefined values.

Note: This function depends on calculateAge, which has a timezone issue flagged separately.


570-578: LGTM - Clean throwing wrapper.

The function follows the established validation pattern in the codebase by delegating to checkPlayerEligibility and throwing via result.validate().


588-596: LGTM - Useful boolean convenience method.

The function provides a clean boolean API by delegating to checkPlayerEligibility and converting the result to true/false based on error presence.

test/validation.test.ts (3)

1008-1138: LGTM - Comprehensive test coverage.

The test suite for checkPlayerEligibility is excellent, covering:

  • No restrictions scenario
  • Missing/invalid date of birth handling
  • Minimum and maximum age boundaries
  • Combined age range validation
  • Edge cases (exact age requirements, zero minimum age)

The tests verify both the absence of errors in valid cases and the presence of specific error messages in invalid cases.


1140-1165: LGTM - Adequate coverage for throwing wrapper.

The tests verify the key throwing behaviors:

  • No exception for eligible players
  • Correct exception messages for ineligible players (too young, too old, missing DOB)
  • No exception when no restrictions exist

1167-1197: LGTM - Complete boolean wrapper coverage.

The tests verify the boolean return values across all scenarios:

  • True for eligible players
  • False for all ineligibility reasons
  • Partial restriction handling (minAge-only, maxAge-only)

hoegerma
hoegerma previously approved these changes Jan 26, 2026
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants